package com.lsh.threadpool;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/12/17 3:08 下午
 * @desc ：//1.创建可定时线程池
 */
public class NewScheduledThreadPool {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
        String format = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        System.out.println(format);
        for (int i = 0; i < 10 ; i++) {
            int finalI = i;
            scheduledExecutorService.schedule(() ->{
                System.out.println(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)+" :"+Thread.currentThread().getName()+"从定时线程池执行线程"+ finalI);
            },2, TimeUnit.SECONDS);

        }
    }
}
